﻿namespace TfsCloudDeploy.Workflow.Core
{
    using Microsoft.TeamFoundation.VersionControl.Client;
    using Microsoft.TeamFoundation.VersionControl.Common;

    /// <summary>
    /// Reflected from: Microsoft.TeamFoundation.VersionControl.Client.ServerMapping&lt;T&gt;.
    /// Assembly: Microsoft.TeamFoundation.VersionControl.Controls, Version=10.0.0.0.
    /// Added one additional property, BaselineVersion, that did not exist in the original ServerMapping&lt;T&gt; class.
    /// </summary>
    public class ServerMapping<T>
    {
        // Fields
        internal static readonly string DepthOneString;
        private RecursionType m_depth;
        private T m_mappedTo;
        private string m_serverItem;
        private WorkingFolderType m_type;
        private string m_baselineVersion = "T"; // Default baseline version = tip/latest.

        // Methods
        static ServerMapping()
        {
            ServerMapping<T>.DepthOneString = "*";
        }

        public ServerMapping(string serverItem, T mappedItem, WorkingFolderType mappingType)
            : this(serverItem, mappedItem, mappingType, RecursionType.Full)
        {
        }

        public ServerMapping(string serverItem, T mappedItem, WorkingFolderType mappingType, RecursionType depth)
        {
            this.m_serverItem = serverItem;
            this.m_mappedTo = mappedItem;
            this.m_type = mappingType;
            this.m_depth = depth;
        }

        public ServerMapping(string serverItem, T mappedItem, WorkingFolderType mappingType, RecursionType depth, string baselineVersion)
        {
            this.m_serverItem = serverItem;
            this.m_mappedTo = mappedItem;
            this.m_type = mappingType;
            this.m_depth = depth;
            this.m_baselineVersion = baselineVersion;
        }

        // Properties
        public RecursionType Depth
        {
            get
            {
                return this.m_depth;
            }
            set
            {
                this.m_depth = value;
            }
        }

        public string DisplayServerItem
        {
            get
            {
                if (this.m_depth == RecursionType.OneLevel)
                {
                    return VersionControlPath.Combine(this.m_serverItem, ServerMapping<T>.DepthOneString);
                }
                return this.m_serverItem;
            }
        }

        public bool IsCloaked
        {
            get
            {
                return (this.m_type == WorkingFolderType.Cloak);
            }
        }

        public T MappedItem
        {
            get
            {
                return this.m_mappedTo;
            }
        }

        public WorkingFolderType MappingType
        {
            get
            {
                return this.m_type;
            }
        }

        public string ServerItem
        {
            get
            {
                return this.m_serverItem;
            }
        }

        public string BaselineVersion
        {
            get
            {
                return this.m_baselineVersion;
            }
        }
    }


}
